home *** CD-ROM | disk | FTP | other *** search
- /* $VER: IBSearch.ibrx 1.00 2000
- Copyright © 2000 Brian Scott
- Email: bscott@odyssey.apana.org.au
-
- IBSearch.ibrx provides simple searching (optional case sensitive) of
- either IBrowse's GlobalCache, hotlist or GlobalHistory. It can also
- search the hotlist for the current url. Only hotlist searching is
- available for IBrowseV2+.
- */
-
- /* Set path to IBrowse */
- Cdir = ""
- /* Cdir = "IBrowse:" */
-
- OPTIONS results
- addlib('rexxsupport.library',0,-30,0)
-
- call setdefaults()
- call buildgui()
-
- do while ~eof(ca)
- CALL topipe('con')
- in = readln(ca)
- parse var in in1 in2 in3 in4 in5 ; in5 = strip(in5,'b')
- if in1 = "gadget" then CALL gadgets()
- if in1 = "close" then CALL doenv()
- end
-
- EXIT
-
- gadgets:
- select
- when (in2=9) then CALL findcurl()
- when (in3=16) & (in5 ~="") then CALL loadIB(nstr.in5)
- when (in2=8) & (in3 ~="") & (srchfile = sfile.HLfile) then do
- if strok(in3, Cresvdtxt) then do
- CALL topipe('id 0 s 256')
- CALL srchhotlist(in3)
- CALL topipe('id 0 s 512')
- end
- end
- when (in2=8) & (in3 ~="") & (srchfile = sfile.GCfile) then do
- if strok(in3, Hresvdtxt) then do
- CALL topipe('id 0 s 256')
- CALL srchche(in3)
- CALL topipe('id 0 s 512')
- end
- end
- when (in2=8) & (in3 ~="") & (srchfile = sfile.GHfile) then do
- CALL topipe('id 0 s 256')
- CALL srchghlist(in3)
- CALL topipe('id 0 s 512')
- end
- when (in2=5) then srchfile = sfile.in3
- when (in2=6) then do
- case=in3
- tmp=topipe('id 'casebut' gt "'"Case "||cbtxt.case'"')
- end
- otherwise NOP
- end
- tmp=topipe('id 'srchid' s 400')
- RETURN
-
- setdefaults:
- if Cdir="" then do
- Cdir = IBexists()
- if Cdir="" then do
- CALL showmsg("Can''t find IBrowse!", "See readme for script placement instructions.")
- EXIT
- end
- end
- ver2=0
- if IBver() > 20 then ver2=1
-
- LF = '0a'x
-
- envfile="env:_IBSearch.env"
- HLfile=0; GCfile=1; GHfile=2
- sfile.GCfile = Cdir||"Cache/GlobalCache"
- sfile.HLfile = Cdir||"ibrowse-hotlist.html"
- sfile.GHfile = Cdir||"GlobalHistory"
-
- case = 0
- srchtxt = ""
- filechoice = 0
- windowdef= 'width' 400 'height' 133
- if open('env',envfile,'r') then do
- windowt=readln('env')
- parse var windowt wl wt ww wh .
- if (datatype(wt,N) &datatype(wl,N) &datatype(ww,N) & datatype(wh,N) ) then
- windowdef= 'top' wt 'left' wl 'width' ww 'height' wh
- ln=readln('env')
- if EOF('env') then do; close('env'); BREAK; end
- if datatype(ln,N) then filechoice=ln
- ln=readln('env')
- if EOF('env') then do; close('env'); BREAK; end
- if datatype(ln,N) then case=ln
- CALL close('env')
- end
-
- srchfile = sfile.filechoice
-
- cbtxt.0 = "Off"
- cbtxt.1 = "On "
- maxstr = 65535
- Z = D2C(0)
- Cresvdtxt = 'TEXT/PLAIN.HTML.JPEG.IMAGE.PNG or a number.'
- Hresvdtxt = 'BHLFLAGS=NOMENU or a number.'
- font="Helvetica.font"; fsize="11"
- RETURN
-
- doenv:
- if open('w',envfile,'w') then do
- call writeln(ca,'id 0 read')
- windowr=readln(ca)
- CALL writeln('w',windowr)
- call writeln(ca,'id 'file2srch' read')
- filechoice=readln(ca)
- CALL writeln('w',filechoice)
- call writeln(ca,'id 'casebut' read')
- case=readln(ca)
- CALL writeln('w',case)
- CALL close('w')
- end
- RETURN
-
- strok:
- parse arg tst, resvdtxt
- ok=1
- if (pos(upper(tst),resvdtxt)>0) | datatype(tst,'N') then do
- ok=0; CALL showmsg("Entered one of these reserved texts..", resvdtxt)
- tmp=topipe('id 'srchid' gt ""')
- end
- RETURN ok
-
- srchghlist:
- parse arg srchstr
- ostr=srchstr
-
- if ~open('r',srchfile,'r') then do
- CALL showmsg("Can't open..", srchfile)
- RETURN
- end
- chunk = readch('r',maxstr)
- CALL close('r')
-
- eov=pos(LF,chunk)
- chunk=right(chunk,length(chunk)-eov)
- if case then sstrpos = pos(srchstr,chunk) /* Case sensitive */
- else do
- Uchunk = upper(chunk); srchstr = upper(srchstr)
- sstrpos = pos(srchstr,Uchunk)
- end
-
- if (sstrpos = 0) then do
- lft = left(left(ostr,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
-
- cntr = 0
- if case then do
- do while sstrpos ~=0
- Ltargt = lastpos(" ",chunk,sstrpos); Rtargt = pos(LF,chunk,sstrpos)
- ln=substr(chunk,Ltargt,(Rtargt-Ltargt))
- parse var ln " "url(LF)
- if pos(srchstr,url) >0 then do
- cntr = cntr +1; url.cntr = url
- end
- sstrpos = pos(srchstr,chunk,Rtargt)
- end
- end
- else do
- do while sstrpos ~=0
- Ltargt = lastpos(" ",Uchunk,sstrpos); Rtargt = pos(LF,Uchunk,sstrpos)
- ln=substr(chunk,Ltargt,(Rtargt-Ltargt))
- parse var ln " "url(LF)
- if pos(srchstr,upper(url)) >0 then do
- cntr = cntr +1; url.cntr = url
- end
- sstrpos = pos(srchstr,Uchunk,Rtargt)
- end
- end
-
- if cntr = 0 then do
- lft = left(left(ostr,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
- else do
- call topipe('id 'lbid' removenode')
- tmp=topipe('id 'lbid' s 0')
- tmp=topipe('id 'lbid' list 0')
- do i = 1 to cntr
- nn=topipe('id 'lbid' Addnode gt "'url.i'"'); nstr.nn = url.i
- end
- lft = left(left(ostr,19),21,".")
- parse var lft dbstr" " .
- tmp=topipe('id 'lbid' list 1')
- tmp=topipe('id 0 s 8 gt "'''||dbstr||''' found in GlobalHist"')
- end
- RETURN
-
- srchche:
- parse arg srchstr
- ostr=srchstr
- if ~open('r',srchfile,'r') then do
- CALL showmsg("Can't open..", srchfile)
- RETURN
- end
- chunk = readch('r',maxstr)
- CALL close('r')
-
- if case then sstrpos = pos(srchstr,chunk) /* Case sensitive */
- else do
- Uchunk = upper(chunk); srchstr = upper(srchstr)
- sstrpos = pos(srchstr,Uchunk)
- end
-
- if (sstrpos = 0) then do
- lft = left(left(ostr,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
-
- adjurl = ""
- call topipe('id 'lbid' removenode')
- tmp=topipe('id 'lbid' s 0')
- tmp=topipe('id 'lbid' list 0')
- do while sstrpos > 0
- LZ = lastpos(Z,chunk,sstrpos); RZ = pos(Z,chunk,sstrpos)
- fullurl = substr(chunk,LZ+1,(RZ-LZ)-1); adjurl = fullurl
-
- last7 = upper(right(fullurl,7))
- parse var last7 "." extens
- extens = "."||extens
- if (extens = ".") | (pos(extens,".GIF.JPG.HTML.SHTML") = 0) then do
- parse var chunk +RZ cacheNo (Z) mtype (Z)
- adjurl = adjurl||" ("||mtype||")"
- end
-
- nn=topipe('id 'lbid' Addnode gt "'adjurl'"'); nstr.nn = fullurl
- if case then sstrpos = pos(srchstr,chunk,RZ)
- else sstrpos = pos(srchstr,Uchunk,RZ)
- end
-
- lft = left(left(ostr,19),21,".")
- parse var lft dbstr" " .
- tmp=topipe('id 'lbid' list 1')
- tmp=topipe('id 0 s 8 gt "'''||dbstr||''' found in Cache"')
- RETURN
-
- srchhotlist:
- parse arg srchstr
- ostr=srchstr
-
- if ~open('r',srchfile,'r') then do
- CALL showmsg("Can't open..", srchfile)
- RETURN
- end
- chunk = readch('r',maxstr)
- CALL close('r')
-
- cntr = 0
- UZL = '><'
- UZQ = '"'
- DZL = '>'
- DZR = '</A>'
-
- startat=pos("</B><UL>",chunk); endat=lastpos("</UL>",chunk)
- chunk = substr(chunk,startat,endat-startat)
-
- if case then do /* Case sensitive */
- sstrpos = pos(srchstr,chunk)
- if (sstrpos = 0) then do
- lft = left(left(srchstr,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
- do while sstrpos >0
- LZ = lastpos(UZL,chunk,sstrpos); RZ = pos(LF,chunk,sstrpos)
- ln = substr(chunk,LZ,(RZ-LZ))
- parse var ln (UZQ)url(UZQ) . (DZL)dis(DZR)
- tndstr = url||" ("||dis||")"
- if pos(srchstr,tndstr) > 0 then do
- cntr=cntr +1; ndstr.cntr = tndstr; rurl.cntr=url
- end
- sstrpos = pos(srchstr,chunk,RZ)
- end
- end
- else do
- Uchunk = upper(chunk); srchstr = upper(srchstr)
- sstrpos = pos(srchstr,Uchunk)
- if (sstrpos = 0) then do
- lft = left(left(ostr,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
- do while sstrpos >0
- LZ = lastpos(UZL,Uchunk,sstrpos); RZ = pos(LF,Uchunk,sstrpos)
- ln = substr(chunk,LZ,(RZ-LZ))
- parse var ln (UZQ)url(UZQ) . (DZL)dis(DZR)
- tndstr = url||" ("||dis||")"
- if pos(srchstr,upper(tndstr)) > 0 then do
- cntr=cntr +1; ndstr.cntr = tndstr; rurl.cntr=url
- end
- sstrpos = pos(srchstr,Uchunk,RZ)
- end
- end
-
- if cntr >0 then do
- call topipe('id 'lbid' removenode')
- tmp=topipe('id 'lbid' s 0')
- tmp=topipe('id 'lbid' list 0')
- do i = 1 to cntr
- nn=topipe('id 'lbid' Addnode gt "'ndstr.i'"'); nstr.nn = rurl.i
- end
- lft = left(left(ostr,19),21,".")
- parse var lft dbstr" " .
-
- tmp=topipe('id 'lbid' list 1')
- tmp=topipe('id 0 s 8 gt "'''||dbstr||''' found in hotlist"')
- end
- else do
- lft = left(left(str,58),60,".")
- parse var lft str" " .
- CALL showmsg("With Case "||cbtxt.case||" can't find..", "'"||str||"'")
- RETURN
- end
- RETURN
-
- findcurl:
- if ~Show("P","IBROWSE") then do
- CALL showmsg("Error!", "Requires IBrowse to be running!")
- RETURN
- end
- cursf=srchfile
- address "IBROWSE"
- 'QUERY URL'
- in3=result; in2=8; srchfile=sfile.HLfile
- CALL gadgets()
- srchfile=cursf
- RETURN
-
- loadIB: procedure expose Cdir
- parse arg URL
- if ~Show("P","IBROWSE") then do
- address command "run "||Cdir||"IBrowse"
- CALL DELAY(800)
- end
- address "IBROWSE"
- 'GotoURL "'URL'"'
- RETURN
-
- buildgui:
- CALL open(ca,"awnpipe:Search/xc")
- tmp=topipe('title "IBrowse Cache and HotList searcher." defg v a si m sw ps IBROWSE 'windowdef'')
- fontid=topipe('TextAttr gt "'font'" defn 'fsize'')
-
- lbid=topipe('listbrowser font 'fontid' minw 403 minh 50 arrows')
- tmp=topipe('layout weih 0')
- tmp=topipe('layout v si weih 0 weiw 0 font 'fontid'')
-
- if ~ver2 then file2srch=topipe('chooser pu s 'filechoice' cl "HotList|Cache|GlobalHist"')
- else file2srch=topipe('chooser maxn 1 pu cl "HotList|Cache|GlobalHist"')
- casebut=topipe('button pb s 'case' gt "'"Case "||cbtxt.case'" weih 0')
- tmp=topipe('le')
- tmp=topipe('layout v si')
- tmp=topipe('label gt "Search for:" ua font 'fontid'')
- srchid=topipe('string gt "'srchtxt'" lj minc 20 chl')
- srchbut=topipe('button gt "Find current URL in hotlist" weih 0 font 'fontid'')
- tmp=topipe('le')
- tmp=topipe('le')
- tmp=topipe("open")
- tmp=topipe('id 'srchid' s 400')
- RETURN
-
- topipe:
- /* this routine does error checking on lines written to pipe.*/
-
- /*get line to output*/
- parse arg out
-
- /* write to the pipe*/
- call writeln(ca,out)
-
- /*get responce and parse it.*/
- res=readln(ca)
- parse var res res1 res2 .
-
- /* if all is ok return the second part of the responce (usualy the GID)*/
- if res1='ok' then return(res2)
-
- /* something went wrong, we notify the user then exit */
- /*show problem line and responce (reponce may be just a blank line)*/
- CALL showmsg(res, compress(out,LF'"'''CR))
- EXIT
-
- IBexists: procedure
- PARSE SOURCE . . . src .
- rt = ""
- osrc = src; src = UPPER(src)
- strt=length(src)
- rxp=POS('REXX/',src); if rxp>0 then strt=rxp
- flpos=MAX(LASTPOS(':',src,strt),LASTPOS('/',src,strt))
- parse var osrc progdir +flpos nm
- if exists(progdir||"IBrowse") then rt=progdir
- RETURN rt
-
- IBver: procedure expose Cdir
- CALL open('ibr',Cdir||"IBrowse",'r')
- IBchunk=readch('ibr',65000)
- CALL close('ibr')
- parse var IBchunk "$VER:" ib ver .
- RETURN ver
-
- showmsg:
- parse arg ttle, errtxt
- wd = length(ttle)*10
- le=(length(errtxt)*9)+3
- if le>wd then wd=le
- CALL open('caE',"awnpipe:Error/xc")
- call writeln('caE','"'ttle'" ps IBROWSE db a so v width 'wd'')
- call writeln('caE','layout so b 0 v cj gt " 'errtxt' "')
- call writeln('caE','layout cj b 0 weiw 0')
- call writeln('caE','button cj gt " _OK " c')
- call writeln('caE','le')
- call writeln('caE','le')
- call writeln('caE','open')
- do while ~eof('caE')
- in = readln('caE')
- end
- CALL close('caE')
- RETURN
-